package com.skp.shaphan.ui.connectioncontrols;

import java.util.Vector;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;

import com.skp.shaphan.savedConnections.SavedConnection;
import com.skp.shaphan.savedConnections.SavedConnections;

public class SavedConnectionComboBox extends JComboBox {

	public SavedConnectionComboBox() {
		super(createModel());
	}
	
	private static Vector<String> createModel() {
		SavedConnections sc = SavedConnections.getInstance();
		Vector<SavedConnection> savedConnectionList = sc.getConnections();
		Vector<String> list = new Vector<String>();
		for(SavedConnection c : savedConnectionList) {
			list.add(c.getName() + " (" + c.getType() + ")");
		}
		return list;
	}
	
	public void refreshList() {
		this.setModel(new DefaultComboBoxModel(createModel()));
	}
	
	public void setSelectedConnection(int connId) {
		SavedConnections sc = SavedConnections.getInstance();
		this.setSelectedIndex(sc.getIndexForID(connId));
	}
	
	public int getSelectedConnection() {
		SavedConnections sc = SavedConnections.getInstance();
		return sc.getIDforIndex(this.getSelectedIndex());
	}
}
